home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Unix / satan-1.1.1 / perl / domains.pl < prev    next >
Text File  |  1995-04-10  |  2KB  |  111 lines

  1. #
  2. # sift by domains
  3. #
  4. # Output to: 
  5. #
  6. # $all_domains{domain}: hosts in this domain
  7. #
  8. # host_domain{host}: the domain of this host
  9. #
  10. # $domain_count{domain}: number of hosts in this domain
  11. #
  12. # $domain_severities{domain}: nr of vulnerable hosts in domain
  13. #
  14. # $domain_flag: reset whenever the tables are updated. To recalculate,
  15. # invoke make_domain_info().
  16. #
  17. # Standalone usage: perl domains.pl [data directory]
  18.  
  19. #
  20. # Generate domain statistics.
  21. #
  22. sub make_domain_info {
  23.     local($domain, $host);
  24.  
  25.     if ($domain_flag > 0) {
  26.     return;
  27.     }
  28.     $domain_flag = time();
  29.  
  30.     print "Rebuild domain type statistics...\n" if $debug;
  31.  
  32.     %all_domains = ();
  33.     for $host (keys %all_hosts) {
  34.     if ($host =~ /^[\[\]0-9.]+$/) {
  35.         $domain = "unknown";
  36.     } else {
  37.         ($domain = $host) =~ s/^[^.]+\.//;
  38.     }
  39.     $all_domains{$domain} .= "$host ";
  40.     $host_domain{$host} = $domain;
  41.     }
  42.  
  43.     # Cheat, in case the facts file has names not in all-hosts.
  44.  
  45.     for $host (keys %hosttype, keys %severity_host_count) {
  46.     if ($host =~ /^[0-9.]+$/) {
  47.         $domain = "unknown";
  48.     } else {
  49.         ($domain = $host) =~ s/^[^.]+\.//;
  50.     }
  51.     if (!exists($host_domain{$host})) {
  52.         $all_domains{$domain} .= "$host ";
  53.         $host_domain{$host} = $domain;
  54.     }
  55.     }
  56.  
  57.     for $domain (keys %all_domains) {
  58.     $domain_count{$domain} = split(/\s+/, $all_domains{$domain});
  59.     $domain_severities{$domain} = 0;
  60.     for $host (split(/\s+/, $all_domains{$domain})) {
  61.         $domain_severities{$domain}++ if exists($severity_host_type_info{$host});
  62.     }
  63.     }
  64. }
  65.  
  66. #
  67. # erase the domain info tables
  68. #
  69. sub clear_domain_info {
  70.     %all_domains = ();
  71.     %host_domain = ();
  72.     %domain_count = ();
  73.     %domain_severities = ();
  74.     $domain_flag = 0;
  75. }
  76.  
  77. #
  78. # Stand-alone mode
  79. #
  80. if ($running_under_satan == 0) {
  81.     warn "domains.pl in stand-alone mode...";
  82.     $running_under_satan = 1;
  83.     $debug = 1;
  84.     require 'perl/targets.pl';
  85.     require 'perl/severities.pl';
  86.     require 'perl/facts.pl';
  87.  
  88.     &read_all_hosts("$ARGV[0]/all-hosts");
  89.     &read_facts("$ARGV[0]/facts");
  90.     &make_domain_info();
  91.     &make_hosttype_info();
  92.  
  93.     print "Missing domain info\n";
  94.  
  95.     for (keys %hosttype) {
  96.     print "\t$_\n" if !exists($host_domain{$_});
  97.     }
  98.  
  99.     print "\nDomain info\n";
  100.  
  101.     for (keys %all_domains) {
  102.         print "Domain: $_ $domain_severities{$_}/$domain_count{$_}\n";
  103.         for (split(/\s/, $all_domains{$_})) {
  104.             print "\t$_\n";
  105.         }
  106.     }
  107. }
  108.  
  109. 1;
  110.